package com.example.lenovo.demo.presenter.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lenovo.demo.R;
import com.example.lenovo.demo.model.databean.CityHotBean;

import java.util.List;

/**
 * Created by Lenovo on 2017/1/11.
 */

public class CityHot_LvAdapter extends BaseAdapter {
    private List<CityHotBean.DataBean> data;
    private Context context;

    public CityHot_LvAdapter(List<CityHotBean.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            viewHolder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.cityhot_lv_item,viewGroup,false);
            viewHolder.imageView= (ImageView) view.findViewById(R.id.cityhotlv_item_img);
            viewHolder.title= (TextView) view.findViewById(R.id.cityhotlv_tv1);
            viewHolder.subTitle= (TextView) view.findViewById(R.id.cityhotlv_tv2);
            view.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) view.getTag();
        }
        CityHotBean.DataBean dataBean=data.get(i);
        viewHolder.title.setText(dataBean.getName());
        viewHolder.subTitle.setText(dataBean.getSummary());
        Glide.with(context).load(dataBean.getPhoto_url())
                .into(viewHolder.imageView);

        return view;
    }
    class ViewHolder{
        ImageView imageView;
        TextView title,subTitle;
    }
}
